<?php
/**
 * Gold
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Gold
 * @package     Gold_Orderpreparation
 */

/**
 * Flat sales order grid collection
 *
 */
class Gold_Orderpreparation_Model_Mysql4_Sales_Order_Grid_Collection extends Mage_Sales_Model_Mysql4_Order_Grid_Collection
{
   	protected $_isTotals            = false;
   	protected $_aggregatedColumns   = array();
	/**
     * Getter/Setter for isTotals
     *
     * @param null|boolean $flag
     * @return boolean|Mage_Sales_Model_Mysql4_Report_Collection_Abstract
     */
    public function isTotals($flag = null)
    {
        if (is_null($flag)) {
            return $this->_isTotals;
        }
        $this->_isTotals = $flag;
        return $this;
    }
    
    
	/**
     * Set array of columns that should be aggregated
     *
     * @param array $columns
     * @return Mage_Sales_Model_Mysql4_Report_Collection_Abstract
     */
    public function setAggregatedColumns(array $columns)
    {
        if (empty($columns))
        {
        	return $this;
        }
        foreach ($columns as $column => $exp)
        {
        	$this->addExpressionFieldToSelect($column,"$exp({{".$column."}})",array($column=>$column));
        }        
        return $this;
    } 

	/**
     * Retrieve array of columns that should be aggregated
     *
     * @return array
     */
    public function getAggregatedColumns()
    {
        return $this->_aggregatedColumns;
    }
    
	protected function _getSelectedColumns()
    {        
        if ($this->isTotals()) {
            $this->_selectedColumns = $this->getAggregatedColumns();
        }

        return $this->_selectedColumns;
    }
}
